-
Notifications
You must be signed in to change notification settings - Fork 5
Support non-linear skbs for BPF_PROG_TEST_RUN #6118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support non-linear skbs for BPF_PROG_TEST_RUN #6118
Conversation
|
Upstream branch: 56b4d16 |
78417cf to
cdcea0f
Compare
|
Upstream branch: 56b4d16 |
9b38484 to
b7635fc
Compare
cdcea0f to
5ba1e72
Compare
|
Upstream branch: 56b4d16 |
b7635fc to
ed7a304
Compare
5ba1e72 to
c9241b4
Compare
This bit of refactoring aims to simplify how we free memory in bpf_prog_test_run_skb to avoid code duplication. Tested-by: [email protected] Signed-off-by: Paul Chaignon <[email protected]>
This patch reorders the initialization of bpf_prog_test_run_skb to simplify the subsequent patch. Program types are checked first, followed by the ctx init, and finally the data init. With the subsequent patch, program types and the ctx init provide information that is used in the data init. Thus, we need the data init to happen last. Signed-off-by: Paul Chaignon <[email protected]>
This patch adds support for crafting non-linear skbs in BPF test runs for tc programs. The size of the linear area is given by ctx->data_end, with a minimum of ETH_HLEN always pulled in the linear area. If ctx or ctx->data_end are null, a linear skb is used. This is particularly useful to test support for non-linear skbs in large codebases such as Cilium. We've had multiple bugs in the past few years where we were missing calls to bpf_skb_pull_data(). This support in BPF_PROG_TEST_RUN would allow us to automatically cover this case in our BPF tests. LWT program types are currently excluded in this patch. Allowing non-linear skbs for these programs would require a bit more care because they are able to call helpers (ex., bpf_clone_redirect, bpf_redirect) that themselves call eth_type_trans(). eth_type_trans() assumes there are at least ETH_HLEN bytes in the linear area. That may not be true for LWT programs as we already pulled the L2 header via the eth_type_trans() call in bpf_prog_test_run_skb(). In addition to the selftests introduced later in the series, this patch was tested by enabling non-linear skbs for all tc selftests programs and checking test failures were expected. Tested-by: [email protected] Suggested-by: Daniel Borkmann <[email protected]> Signed-off-by: Paul Chaignon <[email protected]>
This patch adds support for a new tag __linear_size in the test loader, to specify the size of the linear area in case of non-linear skbs. If the tag is absent or null, a linear skb is crafted. Signed-off-by: Paul Chaignon <[email protected]>
This patch adds new selftests in the direct packet access suite, to cover the non-linear case. The first six tests cover the behavior of the bounds check with a non-linear skb. The last test adds a call to bpf_skb_pull_data() to be able to access the packet. Note that the size of the linear area includes the L2 header, but for some program types like cgroup_skb, ctx->data points to the L3 header. Therefore, a linear area of 22 bytes will have only 8 bytes accessible to the BPF program (22 - ETH_HLEN). For that reason, the cgroup_skb test cases access the packet at an offset of 8 bytes. Signed-off-by: Paul Chaignon <[email protected]>
|
Upstream branch: 2e36338 |
ed7a304 to
c3d1e88
Compare
c9241b4 to
6c461ae
Compare
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1009867 irrelevant now. Closing PR. |
Pull request for series with
subject: Support non-linear skbs for BPF_PROG_TEST_RUN
version: 8
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1009867